<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller{
    public function index(){
        $this->display();
    } 
    //验证码 lhx
    public function verify(){
		$Verify = new \Think\Verify();
		$Verify->codeSet = '123456789';
		$Verify->fontSize = 13;
		$Verify->length   = 4;
		$Verify->useNoise = false;
		$Verify->entry();
	}

    //lhx 登录动作
    public function logindo(){
    	if(!empty($_POST['code'])){
	        $valid=I('code');
	        $Verify = new \Think\Verify();
	        $res = $Verify->check($valid);
	        if($res != true){
	            $data['status']=101;
	            $data['info']="验证码不正确";
	            $this->ajaxReturn($data);
	        }
	    }
    	$username=I("userName");
    	$password=md5(I("pwd"));
    	$mod=M("admin");
    	$find =$mod->where("username = '{$username}'")->find();
		if ($find) {
				if($find['password'] == $password){
					$_SESSION['admin']=$find;
					$arr ['status'] = 100;
					$arr ['info'] = "登陆成功!";
					$this->ajaxReturn ( $arr );

				}else{
					$arr ['status'] = 101;
					$arr ['info'] = "密码错误!";
					$this->ajaxReturn ( $arr );

				}
		}else{
    		$arr ['status'] = 101;
            $arr ['info'] = "用户不存在";
            $this->ajaxReturn ( $arr );
    	}

    }




}